package 个人密码库.view.outputview;

import 个人密码库.model.Password;
import 个人密码库.util.TablePrinter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ConsoleOutput implements Output {
    @Override
    public void output(List<Password> passwords, String path) {
        List<String> headers = Arrays.asList("编号", "密码", "描述", "更改时间");
        List<List<String>> rows = converter(passwords);

        TablePrinter.printTable(headers, rows);
    }

    private List<List<String>> converter(List<Password> passwords) {
        List<List<String>> outerList = new ArrayList<>();
        for (Password password : passwords) {
            List<String> innerList = new ArrayList<>();
            innerList.add(String.valueOf(password.getId()));
            innerList.add(password.getPassword());
            innerList.add(password.getDescription());
            innerList.add(password.getModificationDate().toString());
            outerList.add(innerList);
        }

        return outerList;
    }
}
